package cn.lili.modules.grab.factory.after;

import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.grab.GrabAfterParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
@RequiredArgsConstructor
public class GrabAfterFactory {

    private final List<GrabAfterService> afterServiceList;

    /**
     * 售后服务列表  工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> serviceList(GrabAfterParam grabParam) {
        GrabAfterService grabAfterService = afterServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAfterService.serviceList(grabParam);
    }

    /**
     * 售后服务类型  工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> serviceTypeList(GrabAfterParam grabParam) {
        GrabAfterService grabAfterService = afterServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAfterService.serviceTypeList(grabParam);
    }

    /**
     * 创建售后服务  工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> createService(GrabAfterParam grabParam) {
        GrabAfterService grabAfterService = afterServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAfterService.createService(grabParam);
    }

    /**
     * 售后服务详情  工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> serviceDetail(GrabAfterParam grabParam) {
        GrabAfterService grabAfterService = afterServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAfterService.serviceDetail(grabParam);
    }

    /**
     * 取消售后服务  工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> serviceCancel(GrabAfterParam grabParam) {
        GrabAfterService grabAfterService = afterServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAfterService.serviceCancel(grabParam);
    }

    /**
     * 上传售后图片  工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> uploadResource(GrabAfterParam grabParam) {
        GrabAfterService grabAfterService = afterServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAfterService.uploadResource(grabParam);
    }

    /**
     * 售后申请单详情  工厂
     *
     * @param grabParam 参数
     */
    public ResultMessage<Object> getOrderRefundInfo(GrabAfterParam grabParam) {
        GrabAfterService grabAfterService = afterServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAfterService.getOrderRefundInfo(grabParam);
    }
}
